// JavaScript Document
// calls php page for variable value, brings in an "=" sign separated string
document.addEventListener("deviceready",onDeviceReady,false);
function onDeviceReady() {
	navigator.splashscreen.hide();	
}

$.get('http://uwfsunchaser.com/haas.php?get_param=value', function (data) 
{
	// string is separated into an array
	// breaking up data=date~FL1*FL2 into date and Fl1*FL2
	var split1 = data.split("~");
	var date = split1[0].split("=");	
	
	/* Assigns variables to class to be displayed in HTML
	 Format: document.getElementById(date00).innerHTML = date[0];*/
	 	
	 //displaying dynamic dates for Florida page
	for (i = 0; i < 6; i++) 
		{
			 var x = "date0" + i;  //creating IDs to be called in HTML 
			document.getElementById(x).innerHTML = date[i];
		}
	
	// displaying dynamic dates for Nation page
	for (i = 0; i < 13; i++) 
		{
			 var x = "date_" + i;
			document.getElementById(x).innerHTML = date[i];
		}
	
	// breaking up devider[1] = FL1*FL2 into Fl1 and FL2		
	var split2 = split1[1].split("*");
	var fl1 = split2[0].split("=");
	var fl2 = split2[1].split("=");	
		
	// displaying 13 dynamic variables for Nation page
	for (i = 0; i < 13; i++) 
		{
			 var x = "fl1_" + i;
			document.getElementById(x).innerHTML = fl1[i];	
		}
	
	// displaying 6 dynamic variables for Florida page
	for (i = 0; i < 6; i++) 
		{
			var x = "fl2_0" + i;
			document.getElementById(x).innerHTML = fl2[i];	
		}
	
	for (i = 0; i < 13; i++) 
		{	
			 var x = "fl1_" + i;
			 var y = "class" + i;
			 	
			if (fl1[i] > 0) 
				  {
					  document.getElementById(x).className="variableFont";
					  document.getElementById(y).className="icon-fixed-width icon-circle-arrow-up  upgG";	//icon-2x
				  }
			  else if(fl1[i] == 0)
				  {
					  document.getElementById(x).className ="variableFont";
					  document.getElementById(y).className="icon-fixed-width icon-minus-sign  upgB";
				  }
			  else if(fl1[i] < 0)
				  {
					  document.getElementById(x).className = "variableFont";
					  document.getElementById(y).className="icon-fixed-width icon-circle-arrow-down  upgR";
				  }
		}
	
	for (i = 0; i < 6; i++) 
		{	
			 var x = "fl2_0" + i;
			 var y = "class_" + i;
			 	
			if (fl2[i] > 0) 
				  {
					  document.getElementById(x).className="variableFont";
					  document.getElementById(y).className="icon-fixed-width icon-circle-arrow-up  upgG";	
				  }
			  else if(fl2[i] == 0)
				  {
					  document.getElementById(x).className ="variableFont";
					  document.getElementById(y).className="icon-fixed-width icon-minus-sign  upgB";
				  }
			  else if(fl2[i] < 0)
				  {
					  document.getElementById(x).className = "variableFont";
					  document.getElementById(y).className="icon-fixed-width icon-circle-arrow-down  upgR";
				  }
		}
}		
)
// checks connection, displays warnings	
.error(function() 
{
	for (i = 0; i < 13; i++) 
		{	
			 var x = "fl1_" + i;
			 var y = "class" + i;
			 var z = "date_" + i;
				document.getElementById(x).className = "variableFont";
				document.getElementById(y).className="icon-fixed-width icon-remove-sign  upgError";
				document.getElementById(z).innerHTML = "Check your internet connection!";
		}
	for (i = 0; i < 6; i++) 
		{
			var x = "fl2_0" + i;
			var y = "class_" + i;
			var z = "date0" + i;
			
				document.getElementById(x).className = "variableFont";
				document.getElementById(y).className="icon-fixed-width icon-remove-sign  upgError";
				document.getElementById(z).innerHTML = "Check your internet connection!";	
		}	
		
		
}// End connection check	
);

/*TEST GRAPH TEST*/
$(document).bind("mobileinit",function(){
	$('#msa01').live('pageshow',function(){
		$.jqplot('chartdiv',  [[[1, 2],[3,5.12],[5,13.1],[7,33.6],[9,85.9],[11,219.9]]]);
	})
});


/*RocknCoder.Pages.manageBarChart = function () {
var pageshow = function () {
updateChart();
$("#refreshBarChart").click(function(){
updateChart();
});
},
pagehide = function () {
$("#refreshBarChart").unbind('click');
},
updateChart= function(){
var barA = parseInt($("#pageBarSliderA").val(),10),
barB = parseInt($("#pageBarSliderB").val(),10),
barC = parseInt($("#pageBarSliderC").val(),10);
showChart(barA, barB, barC);
},
showChart = function(barA, barB, barC){
$.jqplot('barChart', [[[barA,1], [barB,3], [barC,5]]], {
seriesDefaults:{
renderer:$.jqplot.BarRenderer,
shadowAngle: 135,
rendererOptions: {
barDirection: 'horizontal'
},
pointLabels: {show: true, formatString: '%d'}
},
axes: {
yaxis: {
renderer: $.jqplot.CategoryAxisRenderer
}
}
}).replot({clear: true, resetAxes:true});
};
return {
pageshow: pageshow,
pagehide: pagehide
}
}();*/